using Google.Protobuf;
using MyFramework.Singleton;

namespace MyFramework.Network
{
    public class ProtobufManager : Singleton<ProtobufManager>
    {
        public static byte[] Serialize(IMessage message)
        {
            return message.ToByteArray();
        }

        public static T Deserialize<T>(byte[] data) where T : IMessage, new()
        {
            IMessage message = new T();
            return (T)message.Descriptor.Parser.ParseFrom(data);
        }
    }
}